﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ettevotja_muudatus_kanne", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(EttevotjaMuudatusKanne))]
    public class EttevotjaMuudatusKanneSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IEttevotjaMuudatusKanne clazz;
        
        public EttevotjaMuudatusKanneSerializer(IEttevotjaMuudatusKanne clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.EttevotjaId!=null) {
                Writer.WriteStartElement("ettevotja_id");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EttevotjaId))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.EttevotjaAriregistriKood!=null) {
                Writer.WriteStartElement("ettevotja_ariregistri_kood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.EttevotjaAriregistriKood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.EttevotjaArinimi!=null) {
                Writer.WriteStartElement("ettevotja_arinimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EttevotjaArinimi))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.EttevotjaOiguslikVorm!=null) {
                Writer.WriteStartElement("ettevotja_oiguslik_vorm");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EttevotjaOiguslikVorm))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.EttevotjaPiirkond!=null) {
                Writer.WriteStartElement("ettevotja_piirkond");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.EttevotjaPiirkond))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.EttevotjaUusPiirkond!=null) {
                Writer.WriteStartElement("ettevotja_uus_piirkond");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.EttevotjaUusPiirkond))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.RegistrikaardiTyyp!=null) {
                Writer.WriteStartElement("registrikaardi_tyyp");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.RegistrikaardiTyyp))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.RegistrikaardiNr!=null) {
                Writer.WriteStartElement("registrikaardi_nr");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.RegistrikaardiNr))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeId!=null) {
                Writer.WriteStartElement("kande_id");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandeId))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeNr!=null) {
                Writer.WriteStartElement("kande_nr");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.KandeNr))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeKpv!=null) {
                Writer.WriteStartElement("kande_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.KandeKpv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeLiik!=null) {
                Writer.WriteStartElement("kande_liik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.KandeLiik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeLiikTekst!=null) {
                Writer.WriteStartElement("kande_liik_tekst");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandeLiikTekst))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeStaatuseMuutus!=null) {
                Writer.WriteStartElement("kande_staatuse_muutus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandeStaatuseMuutus))).ToString());
                Writer.WriteEndElement();
            }
            for (int x = 0; ((clazz.Kandeelement != null) 
                        && (x < clazz.Kandeelement.Count)); x = (x + 1)) {
                if (clazz.Kandeelement[x]!=null) {
                    Writer.WriteStartElement("kandeelement");
                    global::Xtee.Core.SerializationMetadata metaKandeelement = this.GetMetaData(clazz.Kandeelement[x]);
                    Writer.WriteTypeAttribute(metaKandeelement.TypeQualifiedName.Namespace, metaKandeelement.TypeQualifiedName.Name);
                    metaKandeelement.NewSerializer(clazz.Kandeelement[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ettevotja_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>ettevotja_id");
                }
                clazz.EttevotjaId = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ettevotja_id")).Value;
            }
            if (Reader.LocalName=="ettevotja_ariregistri_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>ettevotja_ariregistri_kood");
                }
                clazz.EttevotjaAriregistriKood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("ettevotja_ariregistri_kood")).Value;
            }
            if (Reader.LocalName=="ettevotja_arinimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>ettevotja_arinimi");
                }
                clazz.EttevotjaArinimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ettevotja_arinimi")).Value;
            }
            if (Reader.LocalName=="ettevotja_oiguslik_vorm") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>ettevotja_oiguslik_vorm");
                }
                clazz.EttevotjaOiguslikVorm = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ettevotja_oiguslik_vorm")).Value;
            }
            if (Reader.LocalName=="ettevotja_piirkond") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>ettevotja_piirkond");
                }
                clazz.EttevotjaPiirkond = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("ettevotja_piirkond")).Value;
            }
            if (Reader.LocalName=="ettevotja_uus_piirkond") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>ettevotja_uus_piirkond");
                }
                clazz.EttevotjaUusPiirkond = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("ettevotja_uus_piirkond")).Value;
            }
            if (Reader.LocalName=="registrikaardi_tyyp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>registrikaardi_tyyp");
                }
                clazz.RegistrikaardiTyyp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("registrikaardi_tyyp")).Value;
            }
            if (Reader.LocalName=="registrikaardi_nr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>registrikaardi_nr");
                }
                clazz.RegistrikaardiNr = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("registrikaardi_nr")).Value;
            }
            if (Reader.LocalName=="kande_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>kande_id");
                }
                clazz.KandeId = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kande_id")).Value;
            }
            if (Reader.LocalName=="kande_nr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>kande_nr");
                }
                clazz.KandeNr = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("kande_nr")).Value;
            }
            if (Reader.LocalName=="kande_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>kande_kpv");
                }
                clazz.KandeKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("kande_kpv")).Value;
            }
            if (Reader.LocalName=="kande_liik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>kande_liik");
                }
                clazz.KandeLiik = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("kande_liik")).Value;
            }
            if (Reader.LocalName=="kande_liik_tekst") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>kande_liik_tekst");
                }
                clazz.KandeLiikTekst = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kande_liik_tekst")).Value;
            }
            if (Reader.LocalName=="kande_staatuse_muutus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>kande_staatuse_muutus");
                }
                clazz.KandeStaatuseMuutus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kande_staatuse_muutus")).Value;
            }
            if (Reader.LocalName=="kandeelement") {
                clazz.Kandeelement = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatusKandeelement>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "kandeelement")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatus_kanne>kandeelement");
                    }
                    global::Xtee.Core.SerializationMetadata metaKandeelement = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatusKandeelement>(Reader, "ettevotja_muudatus_kandeelement", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                    global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatusKandeelement item = metaKandeelement.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IEttevotjaMuudatusKandeelement>();
                    clazz.Kandeelement.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("kandeelement");
                        metaKandeelement.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
            }
        }
    }
}
